<template>
	<div class="system-role-container layout-padding">
		<div class="system-role-padding layout-padding-auto layout-padding-view">
			<div class="system-user-search mb15">
				 
				<el-button type="primary" icon="ele-Search" @click="handleQuery"> 查询 </el-button>
				 
			</div>
			<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
				<el-table-column type="index" label="序号" width="60" />
				<el-table-column prop="admin_id" label="操作员" show-overflow-tooltip></el-table-column>
				 
				<el-table-column prop="title" label="操作"  min-width="120" />
                <el-table-column prop="url" label="访问链接"  min-width="160" />
                <el-table-column prop="type" label="访问方式"  min-width="100" />
                <el-table-column prop="ip"  label="来源IP" min-width="160" />
				<el-table-column prop="args"  label="访问参数" min-width="160" />
                <el-table-column prop="task_time" label="执行耗时"  min-width="100" />
				<el-table-column prop="create_time" label="创建时间" min-width="180" ></el-table-column>
				<el-table-column label="操作" width="100">
					<template #default="scope"> 
						<el-button   size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				@size-change="onHandleSizeChange"
				@current-change="onHandleCurrentChange"
				class="mt15"
				:pager-count="5"
				:page-sizes="[10, 20, 30]"
				v-model:current-page="state.tableData.tableParams.pageNum"
				background
				v-model:page-size="state.tableData.tableParams.pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="state.tableData.total"
			>
			</el-pagination>
		</div> 
	</div>
</template>

<script setup lang="ts" name="systemRole">
import { defineAsyncComponent, reactive, onMounted, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';


import { getAPI } from '/@/utils/axios-utils';
import { AdminUserLogApi } from '/@/api-services/api';
import { AdminUserLogOut } from '/@/api-services/models';


// 引入组件
//const RoleDialog = defineAsyncComponent(() => import('/@/views/system/role/dialog.vue'));

// 定义变量内容
const roleDialogRef = ref();
const state = reactive({
	tableData: {
		data: [] as  Array<AdminUserLogOut>,
		total: 0,
		loading: false,
		queryParams: {
			 
		},
		tableParams: {
			mfdata: '',
			pageNum: 1,
			pageSize: 10,
		},
	},
});

// 查询操作
const handleQuery = async () => {
	getTableData()
};

// 重置操作
const resetQuery = () => {
	state.tableData.tableParams.mfdata = ""; 
	getTableData();
};

// 初始化表格数据
const getTableData = async () => {
	state.tableData.loading = true; 
	let params = Object.assign(state.tableData.queryParams, state.tableData.tableParams);
	var res = await getAPI(AdminUserLogApi).adminUserLogList(params);

	state.tableData.data =  res.data.data ?? [];
	state.tableData.total = res.data.count;
	setTimeout(() => {
		state.tableData.loading = false;
	}, 500);
};
// 打开新增角色弹窗
const onOpenAddRole = (type: string) => {
	roleDialogRef.value.openDialog(type);
};
// 打开修改角色弹窗
const onOpenEditRole = (type: string, row: Object) => {
	roleDialogRef.value.openDialog(type, row);
};
// 删除角色
const onRowDel =  (row: any) => {
	ElMessageBox.confirm(`此操作将永久删除，是否继续?`, '提示', {
		confirmButtonText: '确认',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then( async() => {			
			let params = { id: row.id };
			var res = await getAPI(AdminUserLogApi).adminUserLogDel(params);
			if( res.data.code == 0){
				getTableData();
			}else{
				ElMessage.success(res.data.message);
			}
		})
		.catch(() => {});
};
// 分页改变
const onHandleSizeChange = (val: number) => {
	state.tableData.tableParams.pageSize = val;
	getTableData();
};
// 分页改变
const onHandleCurrentChange = (val: number) => {
	state.tableData.tableParams.pageNum = val;
	getTableData();
};
// 页面加载时
onMounted(() => {
	getTableData();
});
</script>

<style scoped lang="scss">
.system-role-container {
	.system-role-padding {
		padding: 15px;
		.el-table {
			flex: 1;
		}
	}
}
</style>
